package com.shining.utils;

import org.json.JSONObject;

import com.shining.model.UserInfo;

public class JsonToString
{
	private static JsonToString jsonToString = null;
	private static String path;

	private JsonToString(String values)
	{
		path = values;
	}

	public static JsonToString getInstance(String values)
	{
		if (jsonToString == null)
		{
			return new JsonToString(values);
		}
		return jsonToString;
	}

	public UserInfo getObject()
	{
		try
		{
			UserInfo userInfo = new UserInfo();
			JSONObject jsonObject = new JSONObject(path);
			JSONObject userJSON = jsonObject.getJSONObject("user");
			userInfo.setId(userJSON.getInt("id"));
			userInfo.setProvince(userJSON.getString("location"));
			userInfo.setImage(userJSON.getString("profile_image_url"));
			userInfo.setName(userJSON.getString("name"));
			userInfo.setCity(userJSON.getString("city"));
			userInfo.setFans(userJSON.getInt("followers_count"));
			userInfo.setFocus(userJSON.getInt("friends_count"));
			userInfo.setWeibos(userJSON.getInt("statuses_count"));
			return userInfo;
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return null;
	}
}
